package si.yun.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import si.yun.dao.SyCourseMapper;
import si.yun.entity.SyCourse;
import si.yun.entity.SyCourseRecord;
import si.yun.service.SyCourseCheckService;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: 课程审核实现类
 * @Description: TODO
 * @Author: 柴秋生
 * @Date 2021/9/11 11:55
 */
@Service
public class SyCourseCheckServiceImpl implements SyCourseCheckService {
    @Autowired
    private SyCourseMapper syCourseMapper;
    /**
     * 课程审核
     * @Author : 柴秋生
     * @Date : 2021/8/5 9:05
     * @Param : []
     * @Return : java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     *
     */
    @Override
    public List<Map<String, Object>> selCourseCheck(String courseName,String name,String courseNprice) {
        List<Map<String,Object>> selCourseCheck=syCourseMapper.selCourseCheck(courseName,name,courseNprice);
        return selCourseCheck;
    }
    /**
     * 查看课程审核详情
     * @Author : 柴秋生
     * @Date : 2021/8/13 14:33
     * @Param : [courseId, id]
     * @Return : si.yun.utils.JsonData
     */
    @Override
    public List<Map<String, Object>> selCourseCheckInfo(Integer courseId) {
        List<Map<String,Object>> selCourseCheckInfo=syCourseMapper.selCourseCheckInfo(courseId);
        return selCourseCheckInfo;
    }
    /**
     * 课程审核
     * @Author : 柴秋生
     * @Date : 2021/9/10 15:11
     * @Param : [id, courseCstatus]
     * @Return : int
     */
     @Override
    @Transactional
    public int updateCourse(SyCourse s) {
        int updateCourse=syCourseMapper.updateCourse(s);


        SyCourseRecord sc=new SyCourseRecord();
        sc.setCourseId(s.getCourseId());
        sc.setImplementId(s.getCreateId());

        String result="";
        if(s.getCourseCstatus()==6){
            result+="审核通过";
        }else if(s.getCourseCstatus()==5){
            result+="审核不通过";
        }
        sc.setResult(result);
        sc.setRemarks(s.getRemarks());
        sc.setType(2);

        int num = addRecord(sc);

        if(num==0||num==0){
            throw new RuntimeException();
        }
        int sum=updateCourse+num;

        return sum;
    }

    @Transactional
    public int addRecord(SyCourseRecord sc){
        int num = syCourseMapper.addRecord(sc);
        return  num;
    }

    /**
     * 高级检索
     * @Author : 柴秋生
     * @Date : 2021/9/10 16:57
     * @Param : [courseClassId]
     * @Return : si.yun.utils.JsonData
     */
    @Override
    public List<Map<String, Object>> selSuperCourse(Integer courseClassId) {
        List<Map<String, Object>> selSuperCourse=syCourseMapper.selSuperCourse(courseClassId);
        return selSuperCourse;
    }
}
